package com.ss.web.tagmark.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import org.springframework.security.web.WebAttributes;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ss.web.tagmark.utils.AuthContext;

@Controller
public class HomeController extends BaseController {
	/**
	 * 系统首页
	 * 
	 * @param model
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("/")
	public String index(Model model) throws IOException {
		return "index";
	}

	@RequestMapping("/login")
	public String login() {
		if (AuthContext.isLogin()) {
			return redirect("/");
		}
		return "login";
	}

	@RequestMapping("/login-error")
	public String loginError(Model model) {
		if (AuthContext.isLogin()) {
			return redirect("/");
		}
		model.addAttribute("err", "登录失败！");
		return "login";
	}

	@RequestMapping("/error/403")
	public String error(HttpServletRequest request, Model model) {
		model.addAttribute("url", request.getHeader("Referer"));
		Object ex = request.getAttribute(WebAttributes.ACCESS_DENIED_403);
		model.addAttribute("exception", ex);
		return "login";
	}

}
